package com.healthlink.appcloudcalllib.utils;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.healthlink.appcloudcalllib.common.Constants;

public class Out {
    public static void out(String str){

            Log.e("wang",str);


    }
    public static void out2(String str){

            Log.e("wang",str);


    }
    public static void outHttpLog(String str){

            Log.i("wanghttp",str);


    }
   public static void toast(Context context,String str){
        if (isFastToastOk()){
            if (str.equals("No call information was found")){
                Out.out2("过滤");
                return;
            }
            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
        }else {
        }

   }
    private static long lastCheckTime;
    public static boolean isFastCheckOk() {
        boolean flag = false;
        long showTime = System.currentTimeMillis();
        if ((showTime - lastCheckTime) >= 1000) {
            flag = true;
        }
        lastCheckTime = showTime;
        return flag;
    }
    private static long lastToastime;
    public static boolean isFastToastOk() {
        boolean flag = false;
        long showTime = System.currentTimeMillis();
        if ((showTime - lastToastime) >= 1000) {
            flag = true;
        }
        lastToastime = showTime;
        return flag;
    }

    public static long lastMqTime;
    public static boolean isFastMqOk() {
        boolean flag = false;
        long showTime = System.currentTimeMillis();
        if ((showTime - lastMqTime) >= 1000) {
            flag = true;
        }
        lastMqTime = showTime;
        return flag;
    }
    public static String getAndroidId(Context context){
        if (TextUtils.isEmpty(Constants.sn)) {
            String androidId= Settings.Secure.getString(context.getContentResolver(), Settings.System.ANDROID_ID);
            return androidId;
        }else{
            return Constants.sn;
        }


    }
    public static  boolean getNetWorkStatus(Context context){
        // String str = "00:db:3d:c3:18:8b";
        //将获取到的acitvity中的服务给连接管理器

        try {
            ConnectivityManager connectivityManager= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            //调用服务管理类中的网络环境
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            //判断其中的值是否为空和是否连接网络

            if(activeNetworkInfo!=null && activeNetworkInfo.isConnected()  ){
                //连接成功

                Log.i("---sss",activeNetworkInfo.getExtraInfo()+"0");
                return false;
            }else{
                //网络无连接


                return true;
            }
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }

}
